<?php
	//----------------------- INPUT ELEMENTS -------------------//
	$name 			= $this->formText ( 'name', $this->Item['name'], array ('class' => 'txtmedium') );
	
	$quyen_data		= array();
	if(count($this->Items) > 0){
		foreach ($this->Items AS $key => $val){
			$quyen_data[] = $val['module'] . '_' . $val['controller'] . '_' . $val['action'];
		}
	}
?>

<div class="left_content">
	<?php echo $this->render($this->arrParam['controller'] . '/toolbar/left.php');?>
</div>

<div class="right_content">
	<div class="appContent">
		<form action="" method="post" name="appForm" enctype="multipart/form-data">
			<?php echo $this->render($this->arrParam['controller'] . '/toolbar/index.php');?>
			<?php
				//-------------------- SESSAGES ERROR ------------------
				if(count($this->messageError)>0){
					foreach ($this->messageError AS $key => $val){
						echo '<div class="listError" data="'.$key.'" rel="' . $val . '"></div>';
					}
					echo '<div class="thongbaoError goc5">Có lỗi trong quá trình xử lý.</div>';
				} 
			?>
			<div id="tabs">
				<ul>
					<li><a href="#tabs-1">Thông tin chung</a></li>
				</ul>
				<div id="tabs-1">
					<div class="tblForm">
						<div class="tbl_content">
							<table class="tbl" style="width: auto;">
							<?php
							$filter 		= new Zendvn_GetSystem();
							$module 		= $filter->getAll();
							$quyen			= array();
							$i				 = 0;
							foreach ($module AS $key_module => $val_module){
								foreach ($val_module AS $key_controller => $val_controller){
									$controller = explode('-', $key_controller);
									if($controller[0] == 'admin'){
										foreach ($val_controller AS $key_action => $val_action){
											$item		= $key_module . '_' . $key_controller . '_' . $val_action;
											$quyen[] 	= $item;
											if(!in_array($item, $quyen_data)){
												$i++;
							?>
								<tr id="tr<?php echo $i;?>">
									<td class="label" style="width: 120px;"><?php echo $i;?>) Tiêu đề <span class="red">*</span></td>
									<td style="max-width: 600px;">
										<input type="text" class="txtmedium" id="name_<?php echo $i;?>" name="name[]">
										<span id="module_<?php echo $i;?>"><?php echo $key_module;?></span>
										<span>_</span>
										<span id="controller_<?php echo $i;?>"><?php echo $key_controller;?></span>
										<span>_</span>
										<span id="action_<?php echo $i;?>"><?php echo $val_action;?></span>
									</td>
									<td id="load<?php echo $i;?>">
										<a href="javascript:void(0)" style="display: block;" onclick="saveItem('<?php echo $i;?>')"><img src="<?php echo $this->imgUrl . '/system/icon-32-save.png'?>"></a>
									</td>
								</tr>
							<?php
											}
										}
									}
								}
							}
							?>
							</table>
							<script type="text/javascript">
								function saveItem(id){
									if($('#name_' + id).val() == ''){
										alert('Bạn chưa nhập tiêu đề');
										$('#name_' + id) .focus();
									}else{
										$.ajax({
											url: '<?php echo $this->baseUrl('default/ajax/save-permission');?>',
											type: 'POST',
											dataType: 'html',
											data: { 
												name		: $('#name_' + id).val(), 
												p_module	: $('#module_' + id).text(), 
												p_controller: $('#controller_' + id).text(), 
												p_action	: $('#action_' + id).text() 
											},
											beforeSend: function(){
												$('#load' + id).html('');
												$('#load' + id).addClass('dangtai');
										 	},
										 	success: function(html){
										 		$('#tr' + id).fadeOut(1000);
											}
										});
									}
								}
							</script>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
</div>
<div class="clr"></div>	
